package fate.car.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import fate.car.dao.ICarsDao;
import fate.car.pojo.ACar;
import fate.car.pojo.ACheck;
import fate.car.service.ICarsService;
import fate.common.util.PageInfoUtil;
@Service("aICarsService")
public class ICarsServiceImpl implements ICarsService
{
	@Resource
	private ICarsDao carsDao;
	/*查询汽车*/
	@Override
	public List<ACar> findCondListCarsService(PageInfoUtil pageInfoUtil, Map<String, Object> condMap)
	{
		/* 为关键字模糊查询,加%号 */
		if(condMap.get("color") != null)
		{
			condMap.put("color", "%" + condMap.get("color") +"%");
		}
		if(pageInfoUtil !=null)
		{
			/* 分页 */
			Page page = PageHelper.startPage(pageInfoUtil.getCurrentPage(), pageInfoUtil.getPageSize());
			List<ACar> carsList = this.carsDao.findCondList(condMap);
			/* 设置一下总记录数 */
			pageInfoUtil.setTotalRecord(Integer.valueOf(page.getTotal() + ""));
			return carsList ; 
		}
		return this.carsDao.findCondList(condMap);
	}
	//添加汽车信息
	@Override
	public int insertCar(ACar car)
	{
		// TODO Auto-generated method stub
		return carsDao.insert(car);
	}
	//展示车辆
	@Override
	public List<ACar> ListCarsService(PageInfoUtil pageInfoUtil, Map<String, Object> condMap)
	{
		/* 为关键字模糊查询,加%号 */
		if(condMap.get("color") != null)
		{
			condMap.put("color", "%" + condMap.get("color") +"%");
		}
		if(pageInfoUtil !=null)
		{
			/* 分页 */
			Page page = PageHelper.startPage(pageInfoUtil.getCurrentPage(), pageInfoUtil.getPageSize());
			List<ACar> carsList = this.carsDao.ListCars(condMap);
			/* 设置一下总记录数 */
			pageInfoUtil.setTotalRecord(Integer.valueOf(page.getTotal() + ""));
			return carsList ; 
		}
		return this.carsDao.ListCars(condMap);
	}
	//查询检查单信息
	@Override
	public List<ACheck> ListCheckService(PageInfoUtil pageInfoUtil, Map<String, Object> condMap)
	{
		/* 为关键字模糊查询,加%号 */
		if(condMap.get("adminsId") != null)
		{
			condMap.put("adminsId", "%" + condMap.get("adminsId") +"%");
		}
		if(pageInfoUtil !=null)
		{
			/* 分页 */
			Page page = PageHelper.startPage(pageInfoUtil.getCurrentPage(), pageInfoUtil.getPageSize());
			List<ACheck> chenkList = this.carsDao.listCheck(condMap);
			/* 设置一下总记录数 */
			pageInfoUtil.setTotalRecord(Integer.valueOf(page.getTotal() + ""));
			return chenkList ; 
		}
		return this.carsDao.listCheck(condMap);
	}
	//删除汽车信息
	@Override
	public String deleteCars(Map<String, Object> condMap)
	{
		String i = this.carsDao.deleteCar(condMap);
		return i;
	}
	
}
